import java.util.Timer;
import java.util.TimerTask;

import javax.management.timer.TimerMBean;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;


public class ServletContextApplication implements ServletContextListener {
	public static ServletContextApplication sContextApplication;
	public SyncManager _articleSyncManager;
	@Override
	public void contextDestroyed(ServletContextEvent arg0) {
	}

	@Override
	public void contextInitialized(ServletContextEvent arg0) {
		sContextApplication = this;
		Timer timer = new Timer(true);
		timer.scheduleAtFixedRate(new ArticleSyncTask()	, 0, 5000*60);
		
		getArticleSyncManager().synchronize();
	}
	
	public SyncManager getArticleSyncManager()
	{
		if(_articleSyncManager == null)
			_articleSyncManager = new SyncManager();
		return _articleSyncManager;
	}
	
	public static ServletContextApplication sharedContext()
	{
		return sContextApplication;
	}
	
	private class ArticleSyncTask extends TimerTask
	{

		@Override
		public void run() {
			//getArticleSyncManager().synchronize();
		}
		
	}
}
